package com.mooc.yohoshop.ui.detail;

import com.mooc.yohoshop.ApiService;
import com.mooc.yohoshop.entity.BaseEntity;
import com.mooc.yohoshop.network.BaseRepository;
import com.mooc.yohoshop.network.HttpFactory;
import com.mooc.yohoshop.network.HttpType;

import java.util.ArrayList;
import java.util.HashMap;

import io.reactivex.Observable;

public class GoodsDetailRepo extends BaseRepository {
    //请求全部
    public Observable<BaseEntity>requestDetails(ArrayList<HashMap<String,Object>>list){
        return Observable.merge(HttpFactory.factory(HttpType.SIGNTYPE)
                        .getRetrofit().create(ApiService.class)
                        .requestDetail(createBody(list.get(0))),
                HttpFactory.factory(HttpType.SIGNTYPE)
                        .getRetrofit().create(ApiService.class)
                        .requestHomeGoods(createBody(list.get(1))));
    }

    //上拉加载更多推荐
    public Observable<BaseEntity>requestGoods(HashMap<String,Object> map){
        return convertObservable(HttpFactory.factory(HttpType.SIGNTYPE)
                .getRetrofit().create(ApiService.class)
                .requestLoadHomeGoods(createBody(map)));
    }
    //添加购物车
    public Observable<BaseEntity>requestAddCar(HashMap<String,Object> map){
        return convertObservable(HttpFactory.factory(HttpType.UPLOADTYPE)
                .getRetrofit().create(ApiService.class)
                .requestInsertCar(createBody(map)));
    }

}
